package com.longteng.java.web.thread;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;

/**
 * Created by tianqing.wang
 * DATE : 2018/4/22
 * TIME : 上午11:29
 * PROJECT : web-lesson
 * PACKAGE : com.longteng.java.web.thread
 *
 * @author <a href="mailto:celeskyking@163.com">tianqing.wang</a>
 */
public class ThreadPoolDemo {


    private ExecutorService executorService = Executors.newFixedThreadPool(3);

    private ExecutorService one = Executors.newCachedThreadPool();

    private ExecutorService two = Executors.newSingleThreadExecutor();

    private ScheduledExecutorService three =Executors.newSingleThreadScheduledExecutor();

    public void submit(MyTask task){
        this.executorService.submit(task);
    }

    public void close(){
        this.executorService.shutdown();
    }

    public static void main(String[] args) {
        //ThreadPoolDemo demo = new ThreadPoolDemo();
        for(int i=0;i<100;i++){
            //demo.submit(new MyTask());
            //CompletableFuture.runAsync(new MyTask()).whenComplete();
        }
        while (true){
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        //demo.close();

    }




    public static class MyTask implements Runnable {

        @Override
        public void run() {
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread().getName());

        }
    }




}
